package me.hbz.myblog.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import me.hbz.myblog.domain.Site;
import me.hbz.myblog.doman.utils.DBUtils;

public class SiteDAO {

	public Site findById(int id) throws SQLException {

		Connection conn = DBUtils.getConnection();

		String sql = "select * from site where id=?";

		PreparedStatement st = conn.prepareStatement(sql);
		st.setInt(1, id);
		ResultSet rs = st.executeQuery();

		Site site = null;
		while (rs.next()) {
			site = new Site();
			site.setId(rs.getInt("id"));
			site.setTitle(rs.getString("title"));
			site.setLogo(rs.getString("logo"));
			site.setTheme(rs.getString("theme"));
			site.setRemark(rs.getString("remark"));
		}

		DBUtils.closeResource(conn, st, rs);

		return site;

	}

}